package com.logistics;

import com.logistics.utils.configure.Configure;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.jta.JtaTransactionManager;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

import java.util.concurrent.Executor;


@SpringBootApplication
@MapperScan("com.logistics.*.mapper")
@EnableCaching
@EnableAsync
@EnableTransactionManagement
public class LogisticsApplication {

    public static void main(String[] args) {
        SpringApplication.run(LogisticsApplication.class, args);
    }

    @Bean
    public ServerEndpointExporter serverEndpointExporter(){
        return new ServerEndpointExporter();
    }

    @Bean
    public CacheManager cacheManager(){
        return new ConcurrentMapCacheManager("cache");
    }


    @Bean("taskExecutor")
    public Executor taskExecutor(){
        int i = Runtime.getRuntime().availableProcessors();
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        // 核心线程池大小
        executor.setCorePoolSize(16);
        // 最大线程数
        executor.setMaxPoolSize(20);

        executor.setKeepAliveSeconds(60);

        executor.setAwaitTerminationSeconds(60);

        executor.setWaitForTasksToCompleteOnShutdown(true);
        return executor;
    }



}
